import { Injectable } from '@nestjs/common'
import axios from 'axios'

@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello World!'
  }

  async getList(page: number, limit: number) {
    try {
      const res = await axios.get(
        `https://jsonplaceholder.typicode.com/posts?_page=${page}&_limit=${limit}`,
      )
      return res.data.map((item) => {
        return {
          ...item,
          title: `[${page}]-${item.title}`,
        }
      }) || []
    } catch (e) {
      return []
    }
  }
}
